Skip to content

Default versioned API functions to earliest version for older API settings#6280

Open
brtnfld wants to merge 8 commits intoHDFGroup:developfrom
brtnfld:6278
Open

Default versioned API functions to earliest version for older API settings#6280
brtnfld wants to merge 8 commits intoHDFGroup:developfrom
brtnfld:6278

Conversation

@brtnfld
Copy link
Collaborator

@brtnfld brtnfld commented Mar 10, 2026

Fixes #6278

The fix in bin/make_vers:

my $intro_vers = $vers_list[0];
foreach my $hash_vers (@versions) {
    if ($hash_vers < $intro_vers) {
        $api_vers_to_function_vers{$hash_vers}{$name} = 1;
    }
}

For every API version older than a function's introduction version, it now explicitly sets _vers = 1 (earliest). This means:

H5_USE_16_API -> H5Sencode_vers = 1 -> maps to H5Sencode1 (instead of falling through to H5Sencode2)
H5_USE_16_API -> H5Dread_chunk_vers = 1 -> maps to H5Dread_chunk1 (introduced v1.10, versioned in v2.0.0)
Functions already introduced at or before the configured API version are unchanged.

The auto-generated test in test/tapi_version_default.c validates this for every function × API-version combination by compiling the test six times (once per API level: v16, v18, v110, v112, v114, v200) and asserting each _vers macro equals the expected value.

brtnfld and others added 5 commits March 10, 2026 12:05
…tings (HDFGroup#6278)

When a global API version is set (e.g., H5_USE_16_API), functions
introduced after that version now default to their earliest version
(version 1) instead of the latest. This prevents breakage when an
application uses an older API setting but calls functions that were
later versioned.

- Update bin/make_vers to populate version 1 for API levels predating
  a function's introduction
- Regenerate src/H5version.h with the new defaults
- Add auto-generated test (test/tapi_version_default.c) produced by
  make_vers, compiled once per API version level (v16 through v200),
  verifying all _vers macros match expected values
- Register the test variants in test/CMakeLists.txt and
  test/CMakeTests.cmake

Fixes HDFGroup#6278
Replace three parallel lists with ZIP_LISTS (requires CMake 3.17) with
a single API_VERSION_TEST_NUMBERS list, deriving the target name and
compile definitions dynamically from the number.
- Remove harmful quotes around list variables in target_compile_options
  and target_compile_definitions so CMake expands them correctly
- Remove duplicated API_VERSION_TEST_NUMBERS definition from
  CMakeTests.cmake; it is already in scope via include() from
  CMakeLists.txt
- Use TESTING()/PASSED()/H5_FAILED() macros in the generated
  tapi_version_default.c for consistency with other HDF5 tests
- Validate the src/ -> test/ directory substitution in make_vers
  create_test() to fail early if the prefix is unexpected
- Add clarifying comment in test/CMakeLists.txt explaining why
  ADD_H5_EXE cannot be reused for the API version default tests
@brtnfld
Copy link
Collaborator Author

brtnfld commented Mar 10, 2026

The netCDF tst_h_files4.c is calling H5Oopen_by_token and accessing info->u.token, which requires H5O_info2_t (version 2 of the struct, introduced in v1.12). But the build is getting H5O_info1_t (version 1), which has info->u.addr instead of info->u.token.

netcdf needs to:

  1. Update the API version to at least H5_USE_112_API since the code uses v1.12 features (H5O_info2_t / .token)
  2. Explicitly set #define H5O_info_t_vers 2 before including HDF5 headers
  3. Use the versioned name directly: H5O_info2_t instead of H5O_info_t

brtnfld and others added 3 commits March 10, 2026 14:33
When CI configures with a global default API version (e.g.,
HDF5_DEFAULT_API_VERSION=v16), H5pubconf.h defines H5_USE_16_API_DEFAULT
which activates H5_USE_16_API in H5version.h. This caused tests for
newer API versions (v200, etc.) to fail because multiple H5_USE_*_API
blocks were active simultaneously and the earliest one won.

Fix by having the generated test include H5pubconf.h first, #undef all
API version macros, then re-establish only the version under test before
including the remaining headers.
@brtnfld
Copy link
Collaborator Author

brtnfld commented Mar 10, 2026

NetCDF fix, Unidata/netcdf-c#3310

@brtnfld brtnfld moved this from To be triaged to In progress in HDF5 - TRIAGE & TRACK Mar 11, 2026
@brtnfld brtnfld added this to the HDF5 2.2.0 milestone Mar 11, 2026
@brtnfld
Copy link
Collaborator Author

brtnfld commented Mar 11, 2026

NetCDF has been patched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Change default API version of functions introduced after global API version

5 participants